import { $event } from '/utils'
Page({
  data: {
    username: {
      your: '',
      name: '',
      yourname: '',
    },
  },

  // options = 系统传入的 url 参数
  onLoad(options) {
    const username = JSON.parse(options.username || '')
    this.setData({ username })
    wx.setNavigationBarTitle({
      title: username.yourname,
    })
    $event.on('em.megList.refresh', this, () => {
      const pages = getCurrentPages()
      const currentPage = pages[pages.length - 1]
      if (currentPage.route == 'pages/chatroom/chatroom') {
        this.onLoad({ username })
      }
    })
  },

  onUnload() {
    $event.emit('em.chatroom.leave')
  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading()
    //@ts-ignore
    this.selectComponent('#chat').getMore()
    // 停止下拉动作
    wx.hideNavigationBarLoading()
    wx.stopPullDownRefresh()
  },
})
